package com.wxboot.game.eliminate.modules.repository;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wxboot.game.eliminate.modules.proxy.domain.GameLevel;
import com.wxboot.game.eliminate.modules.proxy.service.GameLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository
public class JellyEliminateRepository {

    @Autowired
    private GameLevelService gameLevelService;

    public String getGameLevelMatrix(Integer level) {
        QueryWrapper<GameLevel> wrapper = new QueryWrapper();
        wrapper.eq("level", level);
        GameLevel gameLevel = gameLevelService.getOne(wrapper);
        return gameLevel.getLevelMatrix();
    }

    public void initAllGameLevelMatrix(List<String> matrixList) {
        QueryWrapper<GameLevel> wrapper = new QueryWrapper();
        wrapper.ge("level", 0);
        gameLevelService.remove(wrapper);
        List<GameLevel> gameLevels = new ArrayList<>();

        for (int i = 0; i < matrixList.size(); i++) {
            GameLevel gameLevel = new GameLevel();
            gameLevel.setLevel(i + 1);
            gameLevel.setLevelMatrix(matrixList.get(i));
            gameLevel.setCreateTime(new Date());

            gameLevels.add(gameLevel);
        }

        gameLevelService.saveBatch(gameLevels);
    }

}
